package dao.Impl;


import dao.TorderinfoDao;
import pojo.Tbaseorder;
import pojo.Torderinfo;
import util.BaseDao;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class TorderinfoDaoImpl extends BaseDao implements TorderinfoDao {

    @Override
    public int add(Torderinfo torderinfo) {
        String sql = "insert into t_order_info (base_order_id, goods_id, buy_num, amount)\n" +
                "values (?,?,?,?);";
        return exeU(sql, torderinfo.getBaseOrderId(), torderinfo.getGoodsId(), torderinfo.getBuyNum(), torderinfo.getAmount());
    }

    @Override
    public List<Tbaseorder> list() {
        String sql = "select * from t_base_order";
        List<Tbaseorder> list = new ArrayList<>();
        rs = exeQ(sql);
        try {
            while (rs.next()) {
                Tbaseorder to = new Tbaseorder(rs.getInt(1),
                        rs.getInt(2),
                        rs.getString(3),
                        rs.getString(4),
                        rs.getString(5),
                        rs.getDouble(6),
                        rs.getString(7));
                list.add(to);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            closeAll();
        }
        return list;
    }

}
